package ru.tests.betterprogrammer;

/**
 * TODO: add description
 * Date: 12.08.11 22:13
 *
 * @author Alexander Troshanin
 */
public class Task2 {

    public static void main(String[] args) {
        System.out.println(sumOfTwoLargestElements(new int[]{}));
        System.out.println(sumOfTwoLargestElements(new int[]{10}));
        System.out.println(sumOfTwoLargestElements(new int[]{10,2,3,4,5,6,7,8,9}));
    }

    public static int sumOfTwoLargestElements(int[] a) {
        /*
          Please implement this method to
          return the sum of the two largest numbers in a given array.
         */
        if (a == null) {
            return 0;
        }
        int max1 = 0;
        int max2 = 0;
        for (int c : a) {

            if (c > max1) {
                max2 = max1;
                max1 = c;
            } else if (c > max2) {
                max2 = c;
            }

        }
        return max1 + max2;

    }

}
